#include "CComm.h"
CRefCount::CRefCount() : m_nRef(1) 
{

};
CRefCount::~CRefCount()
{

}

unsigned long CRefCount::AddRef() 
{
	return InterlockedIncrement(&m_nRef);
}
unsigned long CRefCount::Release()
{
	ULONG cRef = InterlockedDecrement(&m_nRef);
	if (cRef == 0) {
		delete this;
	}
	return cRef;
}

CCritSec::CCritSec() {
	InitializeCriticalSection(&m_CritSec);
};
CCritSec::~CCritSec() {
	DeleteCriticalSection(&m_CritSec);
};
void CCritSec::Lock() {
	EnterCriticalSection(&m_CritSec);
};
void CCritSec::Unlock() {
	LeaveCriticalSection(&m_CritSec);
};

CAutoLock::CAutoLock(CCritSec * plock)
{
	m_pLock = plock;
	m_pLock->Lock();
};

CAutoLock::~CAutoLock() {
	m_pLock->Unlock();
};